package com.iefgames.cs.manager;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.mortbay.util.ajax.Continuation;

public final class CometManager {
	public static final Long SUSPEND_TIME = 3 * 10 * 1000l;
	
	private static Map<String, Continuation>  CometMap = new ConcurrentHashMap<String, Continuation>();
	
	public static void set(String uuid, Continuation continuation) {
		CometMap.put(uuid, continuation);
	}
	
	public static Continuation get(String uuid) {
		return CometMap.get(uuid);
	}
	
	public static void remove(String uuid) {
		CometMap.remove(uuid);
	}
	
	public static void resume(String uuid) {
		Continuation continuation = get(uuid);
		if (continuation == null) {
			return ;
		}
		
		continuation.resume();
	}
	
	public static void removeAll() {
		Set<String> keys = CometMap.keySet();
		for(String key : keys) {
			CometMap.remove(key);
		}
	}
	
	public static boolean isOnline(String uuid) {
		return get(uuid) != null ? true : false;
	} 
	
	private CometManager() {}
}
